<div id="mapPage"></div>
<script>
scope.pagedata.apiurl='//apis.map.qq.com/tools/locpicker?search=1&type=1&key='+scope.main.qqmap_ak+'&referer=进云'
if(scope.main.qqmap_ak=='GGFBZ-HSW35-7KSI4-QSYAM-ZU64O-M2BSN'){
	scope.pagedata.apiurl='//apis.map.qq.com/tools/locpicker?search=1&type=1&key=SN2BZ-MKT32-22SU7-COVX6-ZYXAQ-OEF6D&referer=进云'
	scope.pagedata.apiurl +='&sig=PNxkw7vICb6SZW2iEny0cTrEZ09cqE17';
}
console.log(scope.pagedata.apiurl);
scope.pagedata.jiexiaddress=function(address){
	var reg = /.+?(北京|上海|重庆|天津|省|市|自治区|自治州|县|区)/g;
    let myLocation = address.match(reg);
    let provinceName = '';
    let cityName = '';
    let districtName = '';
    if(myLocation != undefined && myLocation != null){
        // 检查是否为直辖市
        if (['北京市', '上海市', '重庆市', '天津市'].includes(myLocation[0])) {
            provinceName = myLocation[0]; // 直辖市既是省也是市
            cityName = myLocation[0];
            districtName = myLocation.length > 1 ? myLocation[1] : ''; // 如果有区信息，则为第三个匹配项
        }else{
            provinceName = myLocation[0];
            // 非直辖市情况下，市和区可能存在，也可能不存在
            cityName = myLocation.length >= 1 ? myLocation[1] : '';
            districtName = myLocation.length >= 2 ? myLocation[2] : '';
        }
    }
	var addressunit = address.replace(provinceName+cityName+districtName, "");
	var pcdinfo={
		'pcd':{'province':provinceName,'city':cityName,'district':districtName},
		'addressunit':addressunit
	}
	return pcdinfo;
}
$('#mapPage').html('<iframe src="'+scope.pagedata.apiurl+'" width="100%" height="100%" style="min-height:500px;border-radius: 10px;" frameborder="0"></iframe>');
    window.addEventListener('message', function(event){
        // 接收位置信息，用户选择确认位置点后选点组件会触发该事件，回传用户的位置信息
        var loc = event.data;
		//console.log('loc');console.log(loc)
        if (loc && loc.module == 'locationPicker') {//防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
		  if(loc.poiname=='我的位置'){
			 var title=loc.poiaddress
		  }else{
			var title=loc.poiname
		  }
		  var pcdinfo=scope.pagedata.jiexiaddress(loc.poiaddress);
		  var item={
			'title':title,
			'address':loc.poiaddress,
			'lat_lng':{'type':'BD09',lat:loc.latlng.lat,lng:loc.latlng.lng},
			'pcd':pcdinfo.pcd,
			'addressunit':pcdinfo.addressunit,
		  }
		  console.log(item);
		  scope.modal_result(item);
        }
    }, false);
</script>